<template>
<div>
    <query-box :queryForm="queryForm" @search="handleSearch(true)"></query-box>
    <table-list :tableData="tableData" @flash="handleSearch"></table-list>
</div>
</template>

<script>
import TableList from './TableList'
import QueryBox from './QueryBox'
export default {
    name: 'OnlineUser',
    components: {
        QueryBox,
        TableList
    },
    data () {
        return {
            tableData: {
                loading: false,
                isSearch: false,
                rows: []
            },
            queryForm: {
                name: null
            }
        }
    },
    created () {
        this.init()
    },
    methods: {
        handleSearch (flag) {
            this.tableData.currentPage = 1
            if (flag) {
                this.tableData.isSearch = true
            }
            this.init()
        },
        init () {
            const {
                name
            } = this.queryForm
            const params = {
                username: name
            }
            this.tableData.loading = true
            this.$get('/online', params).then(res => {
                if (res) {
                    this.tableData.rows = res
                }
            }).finally(() => {
                this.tableData.loading = false
            })
        }
    }
}
</script>
